package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallInfoModel;
import com.mallcloud.mall.mall.service.MallInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-商场基本信息")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/info")
public class MallInfoController {

    private final MallInfoService mallinfoService;

    @ApiOperation("分页")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('mall_info_view')")
    public R<IPage<MallInfoModel>> page(Page page, MallInfoModel mallInfo) {
        return R.ok(mallinfoService.page(page, Wrappers.query(mallInfo)));
    }

    @ApiOperation("查询详情")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_info_view')")
    public R<MallInfoModel> getById(@PathVariable("id") Long id) {
        return R.ok(mallinfoService.getById(id));
    }

    @ApiOperation("新增")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('mall_info_add')")
    public R<Boolean> save(@RequestBody MallInfoModel mallinfo) {
        return R.ok(mallinfoService.save(mallinfo));
    }

    @ApiOperation("修改")
	@PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('mall_info_edit')")
    public R<Boolean> updateById(@RequestBody MallInfoModel mallinfo) {
        return R.ok(mallinfoService.updateById(mallinfo));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_info_del')")
    public R<Boolean> removeById(@PathVariable Long id) {
        return R.ok(mallinfoService.removeById(id));
    }

	@ApiOperation("导出")
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('mall_info_export')")
    public List<MallInfoModel> export(MallInfoModel mallinfo) {
        return mallinfoService.list(Wrappers.query(mallinfo));
    }
}
